<template>
  <a-form ref="dictionaryTypeFormRef" :model="dictionaryTypeModel" :rules="dictionaryTypeFormRule" v-bind="layout">
    <a-form-item name="codeItemId" :label="t('org.dictionary-type.typeCode')">
      <a-input
        v-model:value="dictionaryTypeModel.codeItemId"
        :placeholder="t('org.dictionary-type.formPlhCodeItemId')"
      />
    </a-form-item>

    <a-form-item name="codeItemName" :label="t('org.dictionary-type.typeName')">
      <a-input
        v-model:value="dictionaryTypeModel.codeItemName"
        :placeholder="t('org.dictionary-type.formPlhCodeItemName')"
      />
    </a-form-item>

    <a-form-item name="sortNo" :label="t('org.dictionary-type.sort')">
      <a-input-number
        :min="1"
        :max="9999999"
        style="width: 100%"
        :placeholder="t('org.dictionary-type.formPlhSortNo')"
        v-model:value="dictionaryTypeModel.sortNo"
      />
    </a-form-item>
  </a-form>
</template>
<script lang='ts'>
import { defineComponent, ref } from 'vue'
import dictionaryTypeApi from '/@/api/org/dictionary-type'
import { dictionaryTypeFormRule } from '../interface'
import { useModelForm } from '/@/kit/model-kit'
import { useI18n } from 'vue-i18n'
export default defineComponent({
  props: {
    dictionaryTypeId: String, //数据字典类型id 可以不存在 不存在即为新增页面
    layout: {
      //布局
      type: Object,
      default: () => {
        return {
          labelCol: { span: 4 },
          wrapperCol: { span: 16 },
        }
      },
    },
  },
  setup(props, { emit }) {
    const { t } = useI18n()
    const dictionaryTypeFormRef = ref()
    const dictionaryTypeModel = ref({
      codeItemId: null,
    })

    const { save } = useModelForm(dictionaryTypeFormRef, dictionaryTypeModel, props.dictionaryTypeId, dictionaryTypeApi)

    //提交方法
    const onSubmit = () => save().then((res) => emit('submitSuccess', res.data.data))

    //提供给外部调用的到codeItemId
    const getCodeItemId = () => dictionaryTypeModel.value.codeItemId

    return {
      t,
      dictionaryTypeFormRef,
      dictionaryTypeModel,
      dictionaryTypeFormRule,
      layout: props.layout,
      onSubmit,
      getCodeItemId,
    }
  },
})
</script>